﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;
using System.Data.SqlClient;

namespace BLL
{
    public class TINHTRANGBVBLL
    {
        DataService DB = new DataService();

        public void insert(string tentinhtrangbv)
        {
            string sql = "insert into tinhtrangbv values ('" + tentinhtrangbv + "')";
            DB.ExecuteNonQuery(sql);
        }

        public void update(int idTinhtrang, string tenTinhtrang) {

            string sql = "update tinhtrangbv set tentinhtrangbv = '" + tenTinhtrang + "' where matinhtrangbv = " + idTinhtrang.ToString();
            DB.ExecuteNonQuery(sql);
        }

        public void delete(int idTinhtrang) {
            string sql = "delete from tinhtrangbv where matinhtrangbv = " + idTinhtrang.ToString();
            DB.ExecuteNonQuery(sql);
        }

        public TINHTRANGBV findByName(string name)
        {
            string sql = "select * from tinhtrangbv where tentinhtrangbv = '" + name + "'";

            TINHTRANGBV ttBv = new TINHTRANGBV();

            DataTable table = new DataTable();
            table = DB.ExecuteReader(sql);
            DataRow r = table.Rows[0];

            ttBv.matinhtrangbv = (int)r[0];
            ttBv.tentinhtrangbv = (string)r[1];

            return ttBv;
        }

        public int UnBlock() {
            string sql = "select * from tinhtrangbv where tentinhtrangbv = 'UnBlock'";

            DataTable table = new DataTable();
            table = DB.ExecuteReader(sql);
            DataRow r = table.Rows[0];

            return (int)r[0];
        }

        public int Block()
        {
            string sql = "select * from tinhtrangbv where tentinhtrangbv = 'Block'";

            DataTable table = new DataTable();
            table = DB.ExecuteReader(sql);
            DataRow r = table.Rows[0];

            return (int)r[0];
        }
    }
}
